<template>
	<div class="wrapper">

		<!-- header部分 -->
		<header>
			<p><Back></Back>商家注册</p>
		</header>

		<!-- 表单部分 -->
		<ul class="form-box">
			<li>
				<div class="title">
					商家ID：
				</div>
				<div class="content">
					<input type="text" v-model="business.businessId" placeholder="请输入商家ID">
				</div>
			</li>
			<li>
				<div class="title">
					密码：
				</div>
				<div class="content">
					<input type="password" v-model="business.pass" placeholder="密码">
				</div>
			</li>
			<li>
				<div class="title">
					确认密码：
				</div>
				<div class="content">
					<input type="password" v-model="confirmPassword" placeholder="确认密码">
				</div>
			</li>
			<li>
				<div class="title">
					商家名称：
				</div>
				<div class="content">
					<input type="text" v-model="business.businessName" placeholder="商家名称">
				</div>
			</li>
			<li>
				<div class="title">
					商家地址：
				</div>
				<div class="content">
					<input type="text" v-model="business.businessAddress" placeholder="商家地址">
				</div>
			</li>
			<li>
				<div class="title">
					商家类型：
				</div>
				<div class="content">
					<select v-model="business.orderTypeId">
						<option value="1">快餐</option>
						<option value="2">正餐</option>
						<option value="3">甜点饮品</option>
						<option value="4">生鲜果蔬</option>
						<option value="5">超市便利</option>
						<option value="6">汉堡披萨</option>
					</select>
				</div>
			</li>
		</ul>

		<div class="button-register">
			<button @click="register">注册</button>
		</div>

		<!-- 底部菜单部分 -->
		<Footer></Footer>
	</div>
</template>

<script>
	import Footer from '../components/Footer.vue';
	import Back from '../components/Back.vue';
	
	export default{
		name:'BusinessRegister',
		data(){
			return {
				business:{
					businessId: '',
					pass: '',
					businessName: '',
					businessAddress: '',
					orderTypeId: '1'
				},
				confirmPassword:''
			}
		},
		methods:{
			register(){
				// 表单验证
				if(this.business.businessId === ''){
					alert('商家ID不能为空！');
					return;
				}
				if(this.business.pass === ''){
					alert('密码不能为空！');
					return;
				}
				if(this.business.pass !== this.confirmPassword){
					alert('两次输入的密码不一致！');
					return;
				}
				if(this.business.businessName === ''){
					alert('商家名称不能为空！');
					return;
				}
				if(this.business.businessAddress === ''){
					alert('商家地址不能为空！');
					return;
				}
				
				// 注册请求
				let url = `BusinessController/saveBusiness/${this.business.businessId}/${this.business.pass}/${this.business.businessName}/${this.business.orderTypeId}/${this.business.businessAddress}`;
				this.$axios.post(url).then(response=>{
					if(response.data.code === 200){
						alert('注册成功！');
						this.$router.push({path:'/businessLogin'});
					}else{
						alert('注册失败: ' + response.data.message);
					}
				}).catch(error=>{
					console.error(error);
					alert('注册失败，请稍后重试');
				});
			}
		},
		components:{
			Footer,
			Back
		}
	}
</script>

<style scoped>
	/****************** 总容器 ******************/
	.wrapper {
		width: 100%;
		height: 100%;
	}

	/****************** header部分 ******************/
	.wrapper header {
		width: 100%;
		height: 12vw;
		background-color: #0097FF;
		color: #fff;
		font-size: 4.8vw;

		position: fixed;
		left: 0;
		top: 0;
		z-index: 1000;

		display: flex;
		justify-content: center;
		align-items: center;
	}

	/****************** 表单部分 ******************/
	.wrapper .form-box {
		width: 100%;
		margin-top: 12vw;
		margin-bottom: 4vw;
	}

	.wrapper .form-box li {
		box-sizing: border-box;
		padding: 4vw 3vw 0 3vw;
		display: flex;
		align-items: center;
	}

	.wrapper .form-box li .title {
		flex: 0 0 18vw;
		font-size: 3vw;
		font-weight: 700;
		color: #666;
	}

	.wrapper .form-box li .content {
		flex: 1;
	}

	.wrapper .form-box li .content input,
	.wrapper .form-box li .content select {
		border: none;
		outline: none;
		width: 100%;
		height: 4vw;
		font-size: 3vw;
	}

	.wrapper .button-register {
		width: 100%;
		box-sizing: border-box;
		padding: 4vw 3vw 0 3vw;
	}

	.wrapper .button-register button {
		width: 100%;
		height: 10vw;
		font-size: 3.8vw;
		font-weight: 700;
		color: #fff;
		background-color: #38CA73;
		border-radius: 4px;

		border: none;
		outline: none;
	}
</style> 